import { defineConfig } from 'vite'
import { extname, relative, resolve } from 'path'
import { fileURLToPath } from 'node:url'
import { glob } from 'glob'
import react from '@vitejs/plugin-react'
import dts from 'vite-plugin-dts'
import { libInjectCss } from 'vite-plugin-lib-inject-css'

// https://vitejs.dev/config/
export default defineConfig({
  plugins: [
    react(),
    libInjectCss(),
    dts({ include: ['lib'] })
  ],
  build: {
    lib: {
      name: 'pixijs-viewer',
      entry: resolve(__dirname, 'lib/index.ts'),
      formats: ['umd'], // 这里使用 UMD 格式
    },
    rollupOptions: {
      external: ['react', 'react/jsx-runtime'],
      output: {
        format: 'umd',
        globals: {
          react: 'React',
          'react/jsx-runtime': 'jsxRuntime',
        },
      }
    }
  }
})